import {
	api_getBusSite
} from '../../api/api.transit.js'
export default {
	namespaced: true,
	state: {
		lineId: '',
		detail: null
	},
	mutations: {
		SET_LINE_ID(state, data) {
			state.lineId = data
		},
		SET_DETAIL_LIST(state, data) {
			state.detail = data
		}
	},
	actions: {
		GET_LINE_DETAILS({ rootState,state, commit }) {
			return new Promise((resolve, reject)=>{
				const data = { 
					cityName:rootState.CityName,
					lineId: state.lineId
				}
				api_getBusSite(data)
					.then((res) => {
						if (res.showapi_res_body.busSite) {
							let body = res.showapi_res_body.busSite
							commit('SET_DETAIL_LIST', body)
							resolve(body)
						} else {
							commit('SET_DETAIL_LIST', null)
							reject()
						}
					})
					.catch(() => {
						commit('SET_DETAIL_LIST', null)
						reject()
					})
			})
		}
	}
}